package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.iwhalecloud.bss.kite.client.api.scene.operate.IOperateSceneFuncProdInstService;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.IsOrderSliceServiceAttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteProdInstFunc;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.ztesoft.bss.common.util.ContextUtil;

/**
* @Description: 是否订购切片服务属性联动处理类
*
* @author lyx
* @date 2020年12月30日
* @version V1.0
* @Package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler
*/
@Service
@AttrHandler(IsOrderSliceServiceAttrHandler.class)
public class IsOrderSliceServiceAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData> {

    @Autowired
    IQuerySceneInstService querySceneInstService;
    
    @Autowired
    IOperateSceneFuncProdInstService operateSceneFuncProdInstService;
    
    @Override
    public void handle(KiteAttr attr, KiteInst inst, AttrData data) {
        /**
         * 如果选择了否（1_0000107），需要删除已添加的5G切片
         */
        String sceneInstId = data.getSceneInstId();
        if (KiteStringUtils.equals(attr.getValue(), "1_0000107")) {
            List<KiteProdInstFunc> prodFuncList = querySceneInstService.listProdInstFuncsByProdId(sceneInstId, attr.getGroupId());
            prodFuncList.forEach(prodFunc -> {
                operateSceneFuncProdInstService.removeFuncProdInst(sceneInstId, inst.getInstId(), prodFunc.getProdInstId(),
                    data.getCustId(), ContextUtil.getSimpleLoginInfo().getStaffId().toString());
            });
        }
    }

    @Override
    public void handleStyle(KiteAttr attr, KiteInst inst, AttrData data) {
    }

}
